package com.Logistics.pdusers.service.impl;

import com.Logistics.mycommon.pojo.pdusers.PdAddressBook;
import com.Logistics.pdusers.mapper.PdAddressBookMapper;
import com.Logistics.pdusers.service.PdAddressBookService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 地址簿 服务实现类
 * </p>
 *
 * @author PinDaLogistics
 * @since 2024-08-05
 */
@Service
public class PdAddressBookServiceImpl extends ServiceImpl<PdAddressBookMapper, PdAddressBook> implements PdAddressBookService {

    @Autowired
    private PdAddressBookMapper pdAddressBookMapper;


    @Override
    public List<PdAddressBook> addressByUserId(Integer id) {
        QueryWrapper<PdAddressBook> pdAddressBookQueryWrapper = new QueryWrapper<>();
        pdAddressBookQueryWrapper.eq("user_id",id);
        List<PdAddressBook> pdAddressBooks = pdAddressBookMapper.selectList(pdAddressBookQueryWrapper);
        return pdAddressBooks;
    }

    @Override
    public List<PdAddressBook> selectbyAddressName(String name) {
        if(StringUtils.isNotBlank(name)){
            QueryWrapper<PdAddressBook> pdAddressBookQueryWrapper = new QueryWrapper<>();
            pdAddressBookQueryWrapper.like("name",name);
            List<PdAddressBook> pdAddressBooks = pdAddressBookMapper.selectList(pdAddressBookQueryWrapper);
            return pdAddressBooks;
        }
        return pdAddressBookMapper.selectList(null);

    }


}
